<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
    //角色表
    protected $table = "role";
    public $timestamps = false;

    /**
     * 获取角色信息并分页
     * @return mixed
     */
    public static function getInfo()
    {
        $res = self::orderBy('rank','DESC')->orderBy('create_time','DESC')->paginate(8);
        return $res;
    }
    /**
     * 获取所有角色信息
     * @return mixed
     */
    public static function getInfoAll()
    {
        $res = self::all();
        return $res;
    }
    /**
     * 设置角色状态 启用/禁用
     * @param $id
     * @param $param
     * @return mixed
     */
    public static function setStatus($id,$param)
    {
        if($param == 0){
            $res = self::where('id',$id)->update(['status'=>0]);
        }else{
            $res = self::where('id',$id)->update(['status'=>1]);
        }
        return $res;
    }

    /**
     * 增加角色
     * @param $data
     * @return mixed
     */
    public static function addRole($data)
    {
        $res = self::insert([
           'name'=>$data['name'],
           'rank'=>$data['rank']
        ]);
        return $res;
    }

    /**
     * 删除角色
     * @param $id
     * @return mixed
     */
    public static function delRole($id)
    {
        $res = self::where('id',$id)->delete();
        return $res;
    }
}
